﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

namespace Epic.HandyExtensions
{
    public static class StringExtensions
    {
#pragma warning disable 1591

        #region basic String methods

        public static bool IsNullOrEmpty(this string value)
        {
            return string.IsNullOrEmpty(value);
        }

        public static bool IsNullOrWhiteSpace(this string value)
        {
            return string.IsNullOrWhiteSpace(value);
        }

        public static string IsInterned(this string value)
        {
            return string.IsInterned(value);
        }

        public static string Intern(this string value)
        {
            return string.Intern(value);
        }

        #endregion

        #region comparing

        #region Is

        public static bool Is(this string strA, string strB)
        {
            return string.Equals(strA, strB);
        }
        public static bool Is(this string strA, string strB, StringComparison comparisonType)
        {
            return string.Equals(strA, strB, comparisonType);
        }

        #endregion

        #region BeginWith

        public static bool BeginWith(this string strA, string strB)
        {
            //if (strA.Is(strB)) return true;
            if (strA == null || strB == null) return false;

            return strA.StartsWith(strB);
        }
        public static bool BeginWith(this string strA, string strB, StringComparison comparisonType)
        {
            //if (strA.Is(strB)) return true;
            if (strA == null || strB == null) return false;

            return strA.StartsWith(strB, comparisonType);
        }
        public static bool BeginWith(this string strA, string strB, bool ignoreCase, CultureInfo culture)
        {
            //if (strA.Is(strB)) return true;
            if (strA == null || strB == null) return false;

            return strA.StartsWith(strB, ignoreCase, culture);
        }

        #endregion

        #region FinishWith

        public static bool FinishWith(this string strA, string strB)
        {
            //if (strA.Is(strB)) return true;
            if (strA == null || strB == null) return false;

            return strA.EndsWith(strB);
        }
        public static bool FinishWith(this string strA, string strB, StringComparison comparisonType)
        {
            //if (strA.Is(strB)) return true;
            if (strA == null || strB == null) return false;

            return strA.EndsWith(strB, comparisonType);
        }
        public static bool FinishWith(this string strA, string strB, bool ignoreCase, CultureInfo culture)
        {
            //if (strA.Is(strB)) return true;
            if (strA == null || strB == null) return false;

            return strA.EndsWith(strB, ignoreCase, culture);
        }

        #endregion

        #endregion

        #region ConcatNullYieldNull

        #region object

        public static string ConcatNullYieldNull(this object arg0, object arg1)
        {
            if (arg0 == null || arg1 == null)
                return null;

            return string.Concat(arg0.ToString(), arg1.ToString());
        }
        public static string ConcatNullYieldNull(this object arg0, object arg1, object arg2)
        {
            if (arg0 == null || arg1 == null || arg2 == null)
                return null;

            return string.Concat(arg0.ToString(), arg1.ToString(), arg2.ToString());
        }
        public static string ConcatNullYieldNull(this object arg0, object arg1, object arg2, object arg3)
        {
            if (arg0 == null || arg1 == null || arg2 == null || arg3 == null)
                return null;

            return string.Concat(arg0.ToString(), arg1.ToString(), arg2.ToString(), arg3.ToString());
        }
        public static string ConcatNullYieldNull(this object[] args)
        {
            if (args == null || args.Any(arg => arg == null))
                return null;

            return string.Concat(args.Select(arg => arg.ToString()));
        }
        public static string ConcatNullYieldNull(this IEnumerable<object> args)
        {
            if (args == null || args.Any(arg => arg == null))
                return null;

            return string.Concat(args.Select(arg => arg.ToString()));
        }
        public static string ConcatNullYieldNull(this object arg0, params object[] args)
        {
            if (arg0 == null || args == null || args.Any(arg => arg == null))
                return null;

            return string.Concat(arg0.ToString(), string.Concat(args.Select(arg => arg.ToString())));
        }
        public static string ConcatNullYieldNull(this object arg0, IEnumerable<object> args)
        {
            if (arg0 == null || args == null || args.Any(arg => arg == null))
                return null;

            return string.Concat(arg0.ToString(), string.Concat(args.Select(arg => arg.ToString())));
        }

        #endregion

        #region string

        public static string ConcatNullYieldNull(this string str0, string str1)
        {
            if (str0 == null || str1 == null)
                return null;

            return string.Concat(str0, str1);
        }
        public static string ConcatNullYieldNull(this string str0, string str1, string str2)
        {
            if (str0 == null || str1 == null || str2 == null)
                return null;

            return string.Concat(str0, str1, str2);
        }
        public static string ConcatNullYieldNull(this string str0, string str1, string str2, string str3)
        {
            if (str0 == null || str1 == null || str2 == null || str3 == null)
                return null;

            return string.Concat(str0, str1, str2, str3);
        }
        public static string ConcatNullYieldNull(this string[] values)
        {
            if (values == null || values.Any(value => value == null))
                return null;

            return string.Concat(values);
        }
        public static string ConcatNullYieldNull(this IEnumerable<string> values)
        {
            if (values == null || values.Any(value => value == null))
                return null;

            return string.Concat(values);
        }
        public static string ConcatNullYieldNull(this string str0, params string[] values)
        {
            if (str0 == null || values == null || values.Any(value => value == null))
                return null;

            return string.Concat(str0, string.Concat(values));
        }
        public static string ConcatNullYieldNull(this string str0, IEnumerable<string> values)
        {
            if (str0 == null || values == null || values.Any(value => value == null))
                return null;

            return string.Concat(str0, string.Concat(values));
        }

        #endregion

        #region T

        public static string ConcatNullYieldNull<T>(this T arg0, T arg1)
        {
            if (arg0 == null || arg1 == null)
                return null;

            return string.Concat(arg0.ToString(), arg1.ToString());
        }
        public static string ConcatNullYieldNull<T>(this T arg0, T arg1, T arg2)
        {
            if (arg0 == null || arg1 == null || arg2 == null)
                return null;

            return string.Concat(arg0.ToString(), arg1.ToString(), arg2.ToString());
        }
        public static string ConcatNullYieldNull<T>(this T arg0, T arg1, T arg2, T arg3)
        {
            if (arg0 == null || arg1 == null || arg2 == null || arg3 == null)
                return null;

            return string.Concat(arg0.ToString(), arg1.ToString(), arg2.ToString(), arg3.ToString());
        }
        public static string ConcatNullYieldNull<T>(this T[] args)
        {
            if (args == null || args.Any(arg => arg == null))
                return null;

            return string.Concat(args.Select(arg => arg.ToString()));
        }
        public static string ConcatNullYieldNull<T>(this IEnumerable<T> args)
        {
            if (args == null || args.Any(arg => arg == null))
                return null;

            return string.Concat(args.Select(arg => arg.ToString()));
        }
        public static string ConcatNullYieldNull<T>(this T arg0, params T[] args)
        {
            if (arg0 == null || args == null || args.Any(arg => arg == null))
                return null;

            return string.Concat(arg0.ToString(), string.Concat(args.Select(arg => arg.ToString())));
        }
        public static string ConcatNullYieldNull<T>(this T arg0, IEnumerable<T> args)
        {
            if (arg0 == null || args == null || args.Any(arg => arg == null))
                return null;

            return string.Concat(arg0.ToString(), string.Concat(args.Select(arg => arg.ToString())));
        }

        #endregion

        #endregion

    }
}
